<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>社区论坛 - 宠物邻里互助平台</title>
    <style>
        :root {
            --primary-color: #FFF9C4;
            --secondary-color: #FFECB3;
            --light-bg: #FFFDE7;
            --text-dark: #5D4037;
            --text-light: #8D6E63;
            --border-color: #FFE082;
            --accent-color: #FFD54F;
            --danger-color: #E57373;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
        }

        body {
            background-color: var(--light-bg);
            color: var(--text-dark);
        }

        .dropdown {
            position: relative;
            display: inline-block;
        }

        .dropdown-content {
            display: none;
            position: absolute;
            background-color: white;
            min-width: 180px;
            box-shadow: 0 8px 20px rgba(0,0,0,0.08);
            border-radius: 12px;
            z-index: 1;
            top: 100%;
            left: 0;
            opacity: 0;
            transform: translateY(10px);
            transition: all 0.3s ease;
            border: 1px solid var(--border-color);
            padding: 8px 0;
        }

        .dropdown:hover .dropdown-content {
            display: block;
            opacity: 1;
            transform: translateY(0);
        }

        .dropdown-content a {
            color: var(--text-dark);
            padding: 10px 20px;
            display: block;
            transition: all 0.2s;
            border-radius: 0;
            text-align: left;
            min-width: 100%;
        }

        .dropdown-content a:hover {
            background-color: var(--secondary-color);
            color: var(--text-dark);
            transform: none;
        }

        .user-avatar {
            width: 34px;
            height: 34px;
            border-radius: 50%;
            background-color: var(--secondary-color);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            color: var(--text-dark);
            font-weight: bold;
            font-size: 14px;
        }

        .login-btn {
            background-color: var(--secondary-color);
            color: var(--text-dark) !important;
        }

        .register-btn {
            background-color: var(--primary-color);
            color: var(--text-dark) !important;
            border: 1px solid var(--border-color);
        }

        .logout-btn {
            background-color: rgba(255, 213, 79, 0.1); /* 浅琥珀黄背景，10%透明度 */
            color: #FF8F00 !important; /* 深琥珀色文字 */
            border: 1px solid rgba(255, 213, 79, 0.3); /* 琥珀黄边框 */
            padding: 8px 15px;
            border-radius: 20px;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
        }

        .logout-btn:hover {
            background-color: rgba(255, 213, 79, 0.3); /* 悬停时加深背景至30%透明度 */
            color: #E65100 !important; /* 悬停时加深为橙红色 */
            border-color: rgba(255, 167, 38, 0.5); /* 悬停时加深边框 */
        }

        /* 主容器 */
        .main-container {
            display: flex;
            max-width: 1200px;
            width: 100%;
            margin: 30px auto;
            gap: 20px;
            align-items: flex-start;
        }

        /* 左侧内容区域 */
        .content-area {
            flex: 1;
            min-width: 0;
        }

        /* 右侧用户信息栏 */
        .user-sidebar {
            width: 280px;
            background-color: #fff;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 20px;
            position: sticky;
            top: 90px;
        }

        .user-avatar-large {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            margin: 0 auto 15px;
            display: block;
            border: 3px solid var(--accent-color);
            object-fit: cover;
            box-shadow: 0 4px 12px rgba(255, 213, 79, 0.2);
        }

        .user-name {
            text-align: center;
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 8px;
            color: var(--text-dark);
        }

        .user-level {
            text-align: center;
            font-size: 14px;
            color: var(--text-light);
            margin-bottom: 20px;
            padding: 5px 10px;
            background-color: #f7f7f7;
            border-radius: 12px;
            display: inline-block;
        }

        .user-stats {
            display: flex;
            justify-content: space-around;
            margin-bottom: 20px;
            background-color: #f9f9f9;
            padding: 12px;
            border-radius: 8px;
        }

        .stat-item {
            text-align: center;
            flex: 1;
        }

        .stat-number {
            font-size: 18px;
            font-weight: bold;
            color: var(--accent-color);
            margin-bottom: 3px;
        }

        .stat-label {
            font-size: 12px;
            color: var(--text-light);
        }

        .user-menu {
            list-style: none;
            border-top: 1px solid #eee;
            padding-top: 15px;
            margin-top: 15px;
        }

        .user-menu li {
            padding: 10px 0;
            border-bottom: 1px dashed #eee;
        }

        .user-menu li a {
            color: var(--text-dark);
            text-decoration: none;
            font-size: 14px;
            display: block;
            padding: 8px 15px;
            border-radius: 6px;
            transition: all 0.2s;
            display: flex;
            align-items: center;
        }

        .user-menu li a i {
            margin-right: 10px;
            color: var(--accent-color);
            width: 20px;
            text-align: center;
        }

        .user-menu li a:hover {
            background-color: var(--secondary-color);
            transform: translateX(5px);
        }

        /* 主内容区域 */
        .main-content {
            background-color: #fff;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 25px;
            margin-bottom: 20px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .header h2 {
            font-size: 20px;
            font-weight: 600;
            color: var(--text-dark);
        }

        .post-btn {
            background-color: var(--accent-color);
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 20px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s;
            display: flex;
            align-items: center;
        }

        .post-btn i {
            margin-right: 5px;
        }

        .post-btn:hover {
            background-color: #FFC107;
            transform: translateY(-2px);
        }

        .post-box {
            display: none;
            margin-bottom: 20px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 15px;
            background-color: #f9f9f9;
        }

        .post-box textarea {
            width: 100%;
            height: 100px;
            border: 1px solid #ddd;
            border-radius: 6px;
            padding: 12px;
            margin-bottom: 12px;
            resize: none;
            font-size: 14px;
        }

        .post-box textarea:focus {
            border-color: var(--accent-color);
            outline: none;
        }

        .post-options {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .post-submit {
            background-color: var(--accent-color);
            color: white;
            border: none;
            padding: 6px 20px;
            border-radius: 20px;
            cursor: pointer;
            font-size: 14px;
        }

        .post {
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            background-color: #fff;
            position: relative;
        }

        .post-content {
            margin-bottom: 15px;
            font-size: 15px;
            line-height: 1.6;
        }

        .post-meta {
            font-size: 13px;
            color: var(--text-light);
            margin-bottom: 12px;
            display: flex;
            align-items: center;
        }

        .post-meta i {
            margin-right: 5px;
        }

        .likes {
            font-size: 13px;
            color: var(--text-light);
            margin-bottom: 12px;
            padding: 8px 0;
            border-top: 1px dashed #eee;
            border-bottom: 1px dashed #eee;
            display: flex;
            align-items: center;
        }

        .likes i {
            color: #ff4e4e;
            margin-right: 5px;
        }

        /* ========== 评论区域紧凑化样式 ========== */
        .comments {
            margin-top: 10px;
            background: #FFFDF6;
            border-radius: 6px;
            border: 1px solid rgba(255, 224, 130, 0.5);
            padding: 8px 10px;
        }

        .comment {
            padding: 8px 10px;
            margin-bottom: 6px;
            background: white;
            border-radius: 4px;
            border-left: 2px solid var(--accent-color);
            display: flex;
            flex-wrap: wrap;
            align-items: baseline;
        }

        .comment:last-child {
            margin-bottom: 0;
        }

        .comment-author {
            font-weight: bold;
            font-size: 13px;
            color: #FF8F00;
            margin-right: 8px;
            flex-shrink: 0;
        }

        .comment-content {
            font-size: 13px;
            color: var(--text-dark);
            line-height: 1.4;
            margin-right: 8px;
            flex: 1;
            min-width: 60%;
        }

        .comment-meta {
            font-size: 11px;
            color: var(--text-light);
            flex-shrink: 0;
        }

        /* 评论数量提示 */
        .comment-count-badge {
            display: inline-block;
            background-color: #FFE082;
            color: #5D4037;
            font-size: 11px;
            padding: 1px 6px;
            border-radius: 8px;
            margin-left: 8px;
        }

        /* 评论输入框样式保持不变 */

        .post-actions {
            display: flex;
            align-items: center;
            border-top: 1px solid #eee;
            padding-top: 12px;
            margin-top: 12px;
        }

        .post-action {
            margin-right: 20px;
            color: var(--text-light);
            font-size: 13px;
            cursor: pointer;
            display: flex;
            align-items: center;
        }

        .post-action i {
            margin-right: 5px;
        }

        .post-action:hover {
            color: var(--accent-color);
        }

        /* 新添加的评论框样式 */
        .comment-form-container {
            display: none;
            margin-top: 15px;
            padding: 15px;
            background-color: #f5f5f5;
            border-radius: 8px;
            border: 1px solid #eee;
        }

        .comment-form textarea {
            width: 100%;
            height: 80px;
            border: 1px solid #ddd;
            border-radius: 6px;
            padding: 12px;
            margin-bottom: 12px;
            resize: none;
            font-size: 14px;
        }

        .comment-form textarea:focus {
            border-color: var(--accent-color);
            outline: none;
        }

        .comment-form-buttons {
            display: flex;
            justify-content: flex-end;
        }

        .comment-cancel {
            background-color: #e0e0e0;
            color: #555;
            border: none;
            padding: 6px 15px;
            border-radius: 20px;
            cursor: pointer;
            font-size: 14px;
            margin-right: 10px;
            transition: all 0.2s;
        }

        .comment-cancel:hover {
            background-color: #d0d0d0;
        }

        .comment-submit {
            background-color: var(--accent-color);
            color: white;
            border: none;
            padding: 6px 15px;
            border-radius: 20px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s;
        }

        .comment-submit:hover {
            background-color: #FFC107;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .user-sidebar {
                width: 250px;
            }
        }

        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
            }

            .user-sidebar {
                width: 100%;
                position: static;
                margin-bottom: 20px;
            }

            .nav-links li {
                margin: 0 5px;
            }

            .nav-links a {
                padding: 8px 12px;
                font-size: 14px;
            }
        }

    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>
<jsp:include page="headForum.jsp"></jsp:include>
<div class="main-container">
    <!-- 左侧内容区域 -->
    <div class="content-area">
        <div class="main-content">
            <div class="header">
                <h2><i class="fas fa-comments"></i> 社区论坛</h2>
                <button class="post-btn" id="showPostBox">
                    <i class="fas fa-plus"></i> 发表帖子
                </button>
            </div>

            <form action="${pageContext.request.contextPath}/forum/add" method="post">
                <div class="post-box" id="postBox">
                    <textarea placeholder="分享你的新鲜事..." name="content" required></textarea>
                    <input type="hidden" name="user_id" value="${login_user.user_id}">
                    <div class="post-options">
                        <button type="submit" class="post-submit">
                            <i class="fas fa-paper-plane"></i> 发布
                        </button>
                    </div>
                </div>
            </form>

            <c:forEach items="${forumByIdList}" var="forum">
                <div class="post">
                    <div class="post-content">
                            ${forum.content}
                    </div>
                    <div class="post-meta">
                        <i class="far fa-user"></i> ${login_user.username}
                        <i class="far fa-clock" style="margin-left: 15px;"></i> ${forum.create_time}
                    </div>
                    <div class="likes">
                        <i class="fas fa-heart"></i> ${forum.like_count}人觉得很赞
                    </div>
                    <div class="comments">
                        <div class="comment">
                            <span class="comment-author">Ye.</span>${forum.comment_count}
                            <span class="comment-meta">${forum.create_time}</span>
                        </div>
                    </div>

                    <!-- 修改评论表单部分 -->
                    <div class="comment-form-container" id="commentForm-${forum.share_id}">
                        <form class="comment-form" action="${pageContext.request.contextPath}/comment/addComment" method="post">
                            <input type="hidden" name="share_id" value="${forum.share_id}">
                            <textarea name="content" placeholder="写下你的评论..." required></textarea>
                            <div class="comment-form-buttons">
                                <button type="button" class="comment-cancel" onclick="hideCommentForm(${forum.share_id})">取消</button>
                                <button type="submit" class="comment-submit">发布</button>
                            </div>
                        </form>
                    </div>

                    <div class="comments">
                        <c:forEach items="${forum.comments}" var="comment">
                            <div class="comment">
                                <span class="comment-author">${comment.author_name}</span>${comment.content}
                                <span class="comment-meta">${comment.create_time}</span>
                            </div>
                        </c:forEach>
                    </div>
                    <a href="${pageContext.request.contextPath}/forum/delete?share_id=${forum.share_id}">删除</a>
                    <div class="post-actions">
                        <div class="post-action">
                            <i class="far fa-thumbs-up"></i> 赞
                        </div>
                        <form action="forum/addComment">
                            <div class="post-action" onclick="showCommentForm(${forum.share_id})">
                                <i class="far fa-comment"></i> 评论
                            </div>
                        </form>
                        <div class="post-action">
                            <i class="fas fa-share"></i> 分享
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>

    <!-- 右侧用户栏 -->
</div>

<script>
    // 显示/隐藏发帖框
    document.getElementById('showPostBox').addEventListener('click', function() {
        var postBox = document.getElementById('postBox');
        postBox.style.display = postBox.style.display === 'block' ? 'none' : 'block';
    });

    // 显示评论表单
    function showCommentForm(share_id) {
        // 隐藏所有其他评论框
        document.querySelectorAll('.comment-form-container').forEach(function(form) {
            form.style.display = 'none';
        });

        // 显示当前帖子的评论框
        var commentForm = document.getElementById('commentForm-' + share_id);
        commentForm.style.display = 'block';

        // 滚动到评论框位置
        commentForm.scrollIntoView({ behavior: 'smooth', block: 'nearest' });

        // 聚焦到文本区域
        commentForm.querySelector('textarea').focus();
    }

    // 隐藏评论表单
    // 修正hideCommentForm函数
    function hideCommentForm(share_id) {
        var commentForm = document.getElementById('commentForm-' + share_id);
        commentForm.style.display = 'none';
    }
</script>
</body>
</html>